package com.fenqing.leetcode.code.t2500_2600;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.Arrays;

public class Topic2574 extends Topic {

    @Execute
    public int[] leftRightDifference(int[] nums) {
        int[] leftSums = new int[nums.length + 1];
        int[] rightSums = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            if (i == 0) {
                leftSums[i] = nums[i];
            } else {
                leftSums[i] = leftSums[i - 1] + nums[i];
            }
        }
        for (int i = nums.length - 1; i >= 0; i--) {
            if (i == nums.length - 1) {
                rightSums[i] = nums[i];
            } else {
                rightSums[i] = rightSums[i + 1] + nums[i];
            }
        }
        int[] result = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            result[i] = Math.abs(leftSums[i] - rightSums[i]);
        }
        return result;
    }

    public static void main(String[] args) {
        Topic2574 topic2574 = new Topic2574();
        int[] run = topic2574.run("[10,4,8,3]");
        System.out.println(Arrays.toString(run));
    }

}
